package com.letfox.test.example;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.letfox.ad.dao.ADPlanDao;
import com.letfox.ad.enums.MaterialEnums;
import com.letfox.ad.model.ADPlan;
import com.letfox.ad.user.dao.ADPlanUAccountDao;
import com.letfox.ad.user.model.ADPlanUAccount;
import com.letfox.frm.dao.FRMDictionaryDao;
import com.letfox.frm.dao.FRMFileDao;
import com.letfox.frm.model.FRMDictionary;
import com.letfox.frm.model.FRMFile;
import com.letfox.test.util.MyBatisUtil;
import com.letfox.user.enums.UserEnums;

/**
 * 单元测试
 */
public class FileExample {

	/**
	 * 需要单元测试的时候在取消注释
	 */
	private FRMFileDao fileDao;
	private FRMDictionaryDao frmDictionaryDao;
	private ADPlanDao planDao;
	private ADPlanUAccountDao planRlUAccountDao;
	
	
	@Test
	public void upload(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		try {
			FRMFile file = new FRMFile();
			file.setFileId("ZXX44X1001");
			file.setFileName("赵日天");
			file.setFileSize("12312");
			file.setUpdateTime(new Date());
			file.setCreateTime(new Date());
			file.setFileType("460101XXXXX");
			file.setFileUrl(UserEnums.UserGender.MAN.getValue());
			file.setDel("0");
			fileDao = session.getMapper(FRMFileDao.class);
			fileDao.insert(file);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void frmFile(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		try {
			FRMDictionary file = new FRMDictionary();
			file.setFrmCode("ZXX44X1001");
			file.setFrmName("sss");
			file.setFrmValue("0");
			file.setFrmType("111");
			file.setUpdateTime(new Date());
			file.setCreateTime(new Date());
			frmDictionaryDao = session.getMapper(FRMDictionaryDao.class);
			frmDictionaryDao.insert(file);		
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void saveAD(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		SqlSession session2 = MyBatisUtil.getSqlSession(true);
		try {
			for (int i = 0; i < 15; i++) {
				ADPlan adPlan=new ADPlan();
				adPlan.setAdPlanId(UUID.randomUUID().toString());
				adPlan.setAdPlanName("ADTEST"+new Random().nextInt()*1000);
				adPlan.setDel(MaterialEnums.Date.YES.getValue());
				adPlan.setAdPlanBudgetDaily(new BigDecimal("0"));
				adPlan.setEndTime(new Date());
				adPlan.setStartTime(new Date());
				adPlan.setUpdateTime(new Date());
				adPlan.setCreateTime(new Date());
				adPlan.setCreateBy("system");
				adPlan.setUpdateBy("system");
				planDao = session.getMapper(ADPlanDao.class);
				planDao.insert(adPlan);		
			    ADPlanUAccount adPlanRlUAccount=new ADPlanUAccount();
			    adPlanRlUAccount.setAccountId("ZXXX1001");
			    adPlanRlUAccount.setAdPlanId(adPlan.getAdPlanId());
			    adPlanRlUAccount.setCreateTime(new Date());
			    adPlanRlUAccount.setUpdateTime(new Date());
			    adPlanRlUAccount.setCreateBy("system");
			    adPlanRlUAccount.setUpdateBy("system");
			    adPlanRlUAccount.setDel(MaterialEnums.Date.YES.getValue());
			    planRlUAccountDao = session2.getMapper(ADPlanUAccountDao.class);
			    planRlUAccountDao.insert(adPlanRlUAccount);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

}
